import request from '@/config/axios'

// 采集任务 VO
export interface CrawlerTaskVO {
  id: number // ID
  taskName: string // 任务名称
  releaseTimeFormat: string // 发布时间格式
  targetChannelId: number // 目标栏目id
  downloadRes: number // 采集下载资源
  crawlerUrl: string // 采集url
  crawlerSort: number // 采集顺序(1倒叙 0正序)
  startPage: number // 开始页码
  endPage: number // 结束页码
  totalThread: number // 任务线程数
  timeoutSecond: number // 超时等待时间(秒)
  contentRule: string // 匹配规则
  excludeRule: string // 正文内容过滤规则
  siteId: number // 站点ID
  userId: number // 创建人ID
}

// 采集任务 API
export const CrawlerTaskApi = {
  // 查询采集任务分页
  getCrawlerTaskPage: async (params: any) => {
    return await request.get({ url: `/cms/crawler-task/page`, params })
  },

  // 查询采集任务详情
  getCrawlerTask: async (id: number) => {
    return await request.get({ url: `/cms/crawler-task/get?id=` + id })
  },

  // 新增采集任务
  createCrawlerTask: async (data: CrawlerTaskVO) => {
    return await request.post({ url: `/cms/crawler-task/create`, data })
  },

  // 修改采集任务
  updateCrawlerTask: async (data: CrawlerTaskVO) => {
    return await request.put({ url: `/cms/crawler-task/update`, data })
  },

  // 开始采集任务
  startCrawlerTask: async (id: number) => {
    return await request.get({ url: `/cms/crawler-task/start?id=` + id })
  },
  // 停止采集任务
  stopCrawlerTask: async (id: number) => {
    return await request.get({ url: `/cms/crawler-task/stop?id=` + id })
  },
  // 删除采集任务
  deleteCrawlerTask: async (id: number) => {
    return await request.delete({ url: `/cms/crawler-task/delete?id=` + id })
  },

  // 导出采集任务 Excel
  exportCrawlerTask: async (params) => {
    return await request.download({ url: `/cms/crawler-task/export-excel`, params })
  },
}
